package com.jackeysun.common

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.jackeysun.common.databinding.DialogJkRealTestShowPicFragmentBinding

class DialogFragmentShowPic : DialogFragment(), View.OnClickListener {
    private var mBinding: DialogJkRealTestShowPicFragmentBinding? = null

    private var content = ""

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        content = arguments?.getString("content").toString()

    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = DialogJkRealTestShowPicFragmentBinding.inflate(inflater)
        return mBinding?.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mBinding?.bigPic?.setOnClickListener(this)
        mBinding?.contentContainer?.setOnClickListener(this)
        mBinding?.bigPic?.let {
            val options = RequestOptions() //
                .centerInside()
            Glide.with(view.context).load(content).apply(options).into(it)
        }
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return Dialog(requireContext(), R.style.DialogStyleFull)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.big_pic,
            R.id.content_container -> {
                dismissAllowingStateLoss()
            }
        }
    }
}